import { ComponentsMgr } from "../ecs/Components/ComponentsMgr";
import { DSystem } from "../ecs/system/DSystem";
import { MoveComponent } from "./MoveComponent";
import { PositionComponent } from "./PositionComponent";

export class MoveSystem extends DSystem {

    public bEnable(eid): boolean {
        let components = ComponentsMgr.ins().getEntityById(eid);
        if (!components || components.length < 1) return false;
        let ret = false;
        if (this.find(components, MoveComponent) && this.find(components, PositionComponent)) {
            ret = true;
        }
        return ret;
    }
    public execute(eid) {
        let components = ComponentsMgr.ins().getEntityById(eid);
        let moveComp = this.find(components, MoveComponent) as MoveComponent
        let positionComp = this.find(components, PositionComponent) as PositionComponent
        positionComp.x += moveComp.xSpeed;
        positionComp.y += moveComp.ySpeed;
    }
}